/*
 * @Author: AskMeWhy
 * @Date: 2020-12-27 11:58:47
 * @Last Modified by: AskMeWhy
 * @Last Modified time: 2021-02-05 15:07:20
 */
const app = getApp();
const { AskComponent } = app._require("common/index");
AskComponent({
    properties: {
        noHeader: {
            type: Boolean,
            value: false,
        },
        noFooter: {
            type: Boolean,
            value: false,
        },
    },
    data: {
        list: [
            // {
            //     icon: "todo-list-o",
            //     label: "项目",
            //     dot: "",
            //     path: "/pages/projects-manager/index",
            //     iconImg: "project",
            // },
            {
                icon: "todo-list-o",
                label: "任务",
                dot: "",
                path: "/pages/task-home/index",
                iconImg: "task",
            },
            {
                icon: "todo-list-o",
                label: "首页",
                dot: "",
                path: "/pages/home/index",
                iconImg: "home",
            },
            // {
            //     icon: "todo-list-o",
            //     label: "上报",
            //     dot: "",
            //     path: "/pages/notes/index",
            //     iconImg: "report",
            // },
            {
                icon: "user-o",
                label: "我的",
                dot: "",
                path: "/pages/personal/index",
                iconImg: "personal",
            },
        ],
        active: "",
    },
    pageLifetimes: {
        show() {
            let pageList = getCurrentPages();
            this.setData({
                active: "/" + pageList[pageList.length -1].route,
            });
        },
    },
    lifetimes: {
        attached() {
            // 在组件实例进入页面节点树时执行
            // let pageList = getCurrentPages();
            // this.setData({
            //     active: "/" + pageList[pageList.length - 1].route,
            // });
        },
        detached() {
            // 在组件实例被从页面节点树移除时执行
        },
    },
    methods: {
        handleClick(e) {
            console.log(e);
            let { item } = e.currentTarget.dataset;
            let _url = item.path;
            if (this.data.active === _url) {
                return;
            }
            const whiteList = ["/pages/task-home/index","/pages/notes/index", "/pages/home/index", "/pages/personal/index", "/pages/home/index","/pages/projects-manager/index"];
            if (!whiteList.includes(_url)) {
                let auth = this.checkAuth();
                if (!auth) {
                    return;
                }
            }
            this.setData({
                active: _url,
            });
            wx.switchTab({
                url: _url,
            });
        },
    },
});
